﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace xplang.run
{

    public class SourceBuilder
    {
        public StringBuilder source=new StringBuilder();
        private bool newLine = false;
        private int ident = 0;

        public void clear()
        {
            source = new StringBuilder();
            newLine = false;
            ident = 0;
        }

        public void write(params String[] stmts) 
        {
            if(newLine){
                source.Append("\r\n");
                source.Append(" ".PadLeft(ident*2));
                newLine=false;
            }
            foreach (String stmt in stmts)
                source.Append(stmt);
        }

        public void writeln(params String[] stmts)
        {
            write(stmts);
            newLine = true;
        }

        public void incIdent()        
        {
            ident++;
        }

        public void decIdent()
        {
            ident--;
        }
    }
}
